﻿using AJWPFAdmin.Core.Components.AJTable.ViewModels;
using AJWPFAdmin.Core.Enums;
using AJWPFAdmin.Core.ExtensionMethods;
using AJWPFAdmin.Core.Logger;
using AJWPFAdmin.Core.Models;
using AJWPFAdmin.Core.Models.EF.Tables;
using AJWPFAdmin.Core.Utils;
using AJWPFAdmin.Services.AppointAPI.GoodsInfoQuery;
using AJWPFAdmin.Services.EF;
using AJWPFAdmin.Services.EF.TableExts;
using Masuit.Tools.Reflection;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using Prism.Ioc;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AJWPFAdmin.Services.AppointAPI
{
    public class DefaultAppointAPI : AppointAPIBase
    {
        /// <summary>
        /// 是否关闭客户端上传
        /// </summary>
        private bool _closeClientAPI;

        private SystemConfigKey _fakeConfigKey;

        private HttpClient _httpClient;

        private APIConfig _apiCfg;

        public APIConfig APISettings
        {
            get => _apiCfg;
        }

        public DefaultAppointAPI(ApplicationType appType,
            SystemConfigDictionary cfg,
            IContainerProvider svcProvider) : base(appType, cfg, svcProvider)
        {

        }

        public override string KeyDescription
        {
            get => _closeClientAPI ? _fakeConfigKey.GetDescription() : base.KeyDescription;
        }

        public void SetFakeConfig(SystemConfigKey key)
        {
            _closeClientAPI = true;
            _fakeConfigKey = key;
        }

        //public override async Task<ProcessResult> GetCarInfoAsync(CarInfoParams @params)
        //{
        //    var result = new ProcessResult();
        //    try
        //    {
        //        var json = await _httpClient.GetStringAsync($"{_apiCfg.Url}?plate={@params.CarInfo.CarNo}&company={_apiCfg.CompanyName}");

        //        var carRes = CommonUtil.TryGetJSONObject<CarInfoAPIResponse>(json);

        //        if (@params.CarInfo.EngineNo != carRes.data.engineNumber)
        //        {
        //            @params.CarInfo.EngineNo = carRes.data.engineNumber;
        //        }

        //        if (Enum.TryParse<EmissionStandard>(carRes.data.emissionstage, out var emissionStd))
        //        {
        //            if (@params.CarInfo.EmissionStandard != emissionStd)
        //            {
        //                @params.CarInfo.EmissionStandard = emissionStd;
        //            }
        //        }

        //        if (@params.CarInfo.CarBrandModel != carRes.data.carModel)
        //        {
        //            @params.CarInfo.CarBrandModel = carRes.data.carModel;
        //        }

        //        var useNNatureStr = carRes.data.useNNature;

        //        if (!string.IsNullOrWhiteSpace(useNNatureStr))
        //        {
        //            var parentId = (long)SystemDictionaryExt.SystemDictionaryKey.使用性质;
        //            var useDescDic = db.SystemDictionaries.AsNoTracking()
        //                .FirstOrDefault(p =>p.ParentId == parentId && p.Name == useNNatureStr);
        //            if (useDescDic != null && @params.CarInfo.UsageDescCode != useDescDic.Code)
        //            {
        //                @params.CarInfo.UsageDescCode = useDescDic.Code;
        //                @params.CarInfo.UsageDescription = useDescDic.Name;
        //            }
        //        }

        //        if (@params.CarInfo.TeamName != carRes.data.fleet)
        //        {
        //            @params.CarInfo.TeamName = carRes.data.fleet;
        //        }

        //        var truckTypeStr = carRes.data.carType;

        //        if (!string.IsNullOrWhiteSpace(truckTypeStr))
        //        {
        //            var parentId = (long)SystemDictionaryExt.SystemDictionaryKey.货车;
        //            var truckType = db.SystemDictionaries.AsNoTracking()
        //                .FirstOrDefault(p =>p.ParentId == parentId && p.Name == truckTypeStr);
        //            if (truckType != null && @params.CarInfo.TruckTypeCode != truckType.Code)
        //            {
        //                @params.CarInfo.TruckTypeCode = truckType.Code;
        //                @params.CarInfo.TruckTypeName = truckType.Name;
        //            }
        //        }

        //        if (@params.CarInfo.VIN != carRes.data.vin)
        //        {
        //            @params.CarInfo.VIN = carRes.data.vin;
        //        }

        //        if (!string.IsNullOrWhiteSpace(carRes.data.registerTime))
        //        {
        //            var regDate = carRes.data.registerTime.TryGetDate();
        //            if (regDate != @params.CarInfo.RegDate)
        //            {
        //                @params.CarInfo.RegDate = regDate;
        //            }
        //        }

        //        if (!string.IsNullOrWhiteSpace(carRes.data.driving_image))
        //        {
        //            var img = CommonUtil
        //            .AJSerializeObject(new string[] { carRes.data.driving_image });
        //            if (@params.CarInfo.VehicleLicense != img)
        //            {
        //                @params.CarInfo.VehicleLicense = img;
        //            }
        //        }

        //        if (@params.CarInfo.Owner != carRes.data.owner)
        //        {
        //            @params.CarInfo.Owner = carRes.data.owner;
        //        }

        //        if (!string.IsNullOrWhiteSpace(carRes.data.list_image))
        //        {
        //            var img = CommonUtil
        //            .AJSerializeObject(new string[] { carRes.data.list_image });
        //            if (@params.CarInfo.Attachments != img)
        //            {
        //                @params.CarInfo.Attachments = img;
        //            }
        //        }

        //        if (!string.IsNullOrWhiteSpace(carRes.data.goods))
        //        {
        //            @params.CarInfo.GoodsName = carRes.data.goods;
        //            @params.CarInfo.GoodsVolume = carRes.data.goodsUnit.TryGetDecimal();
        //        }

        //        result.SetSuccess(@params.CarInfo);

        //    }
        //    catch (Exception e)
        //    {
        //        var keyDesc = Config.Key.GetDescription();
        //        result.SetError($"{keyDesc} 获取车辆信息异常:{e.Message}");
        //        _logger.Error($"{keyDesc} 获取车辆信息异常", e);
        //    }
        //    return result;
        //}

        public override Task ConvertToCustomConfig(bool isReal)
        {
            _customAPIConfig = _apiCfg = CommonUtil.TryGetJSONObject<APIConfig>(Config.StringValue) ?? new APIConfig();
            if (isReal)
            {
                _httpClient = new HttpClient();
            }
            else
            {
                _ = GetSchemas();
            }
            return Task.CompletedTask;
        }

        public override void UpdateConfig(ref DbService db)
        {
            Config.BooleanValue = Checked;

            var props = _customAPIConfig.GetType().GetRuntimeProperties();

            var jobj = new JObject
            {
                {nameof(APISettings.CloseClientAPI), APISettings.CloseClientAPI}
            };

            foreach (var shcema in Schemas)
            {
                var prop = props.FirstOrDefault(p => p.Name == shcema.Field);
                if (prop == null)
                {
                    continue;
                }
                //prop.SetValue(_customAPIConfig, shcema.Value);
                jobj.Add(prop.Name, shcema.Value == null ? null : JToken.FromObject(shcema.Value));
            }

            var key = Config.Key;
            var dbCfg = db.SystemConfigDictionaries.FirstOrDefault(p => p.Key == key);
            if (dbCfg != null)
            {
                dbCfg.BooleanValue = Checked;
                dbCfg.StringValue = CommonUtil.AJSerializeObject(jobj);
                db.Entry(dbCfg).State = EntityState.Modified;
            }
        }

        public new void Dispose()
        {
            _httpClient?.Dispose();
        }

        public class APIConfig : BindableBase
        {
            private string _url;
            /// <summary>
            /// 接口地址
            /// </summary>
            [DynamicFormItemDefine("接口地址")]
            public string Url
            {
                get => _url;
                set => SetProperty(ref _url, value);
            }

            private string _companyName;
            /// <summary>
            /// 公司名称
            /// </summary>
            [DynamicFormItemDefine("公司名称")]
            public string CompanyName
            {
                get => _companyName;
                set => SetProperty(ref _companyName, value);
            }

            private string _appId;
            /// <summary>
            /// AppId
            /// </summary>
            [DynamicFormItemDefine("应用id")]
            public string AppId
            {
                get => _appId;
                set => SetProperty(ref _appId, value);
            }

            private string _appSecret;
            /// <summary>
            /// AppSecret
            /// </summary>
            [DynamicFormItemDefine("应用密钥")]
            public string AppSecret
            {
                get => _appSecret;
                set => SetProperty(ref _appSecret, value);
            }

            private string _dbServer;
            /// <summary>
            /// 数据库地址
            /// </summary>
            [DynamicFormItemDefine("数据库地址")]
            public string DbServer
            {
                get => _dbServer;
                set => SetProperty(ref _dbServer, value);
            }

            private string _dbUserId;
            /// <summary>
            /// 数据库地址
            /// </summary>
            [DynamicFormItemDefine("数据库账户")]
            public string DbUserId
            {
                get => _dbUserId;
                set => SetProperty(ref _dbUserId, value);
            }

            private string _dbPassword;
            /// <summary>
            /// 数据库地址
            /// </summary>
            [DynamicFormItemDefine("数据库密码")]
            public string DbPassword
            {
                get => _dbPassword;
                set => SetProperty(ref _dbPassword, value);
            }

            private string _dbName;
            /// <summary>
            /// 数据库地址
            /// </summary>
            [DynamicFormItemDefine("数据库名称")]
            public string DbName
            {
                get => _dbName;
                set => SetProperty(ref _dbName, value);
            }

            private string _apiDomain;
            /// <summary>
            /// 接口地址
            /// </summary>
            [DynamicFormItemDefine("接口地址")]
            public string ApiDomain
            {
                get => _apiDomain;
                set => SetProperty(ref _apiDomain, value);
            }

            private string _apiToken;
            /// <summary>
            /// 接口令牌
            /// </summary>
            [DynamicFormItemDefine("接口令牌")]
            public string ApiToken
            {
                get => _apiToken;
                set => SetProperty(ref _apiToken, value);
            }

            private string _queryTemplate;
            /// <summary>
            /// 查询模板,目前有 松汀,上海,松汀,AVS1,北京CEM
            /// </summary>
            [DynamicFormItemDefine("查询模板", VbenAdminFormType.Select, OptionsHandler = typeof(DefaultAppointAPIQueryTemplateOptionsHandler))]
            public string QueryTemplate
            {
                get => _queryTemplate;
                set => SetProperty(ref _queryTemplate, value);
            }

            private bool _closeClientAPI;
            /// <summary>
            /// 是否关闭岗亭端的上传,使用手动上传, 这个不参与基础配置, 是属于全局配置
            /// </summary>
            public bool CloseClientAPI
            {
                get => _closeClientAPI;
                set => SetProperty(ref _closeClientAPI, value);
            }

            private string _accessToken;
            public string AccessToken
            {
                get => _accessToken;
                set => _accessToken = value;
            }

            private DateTime? _accessTokenExpireDate;
            public DateTime? AccessTokenExpireDate
            {
                get => _accessTokenExpireDate;
                set => _accessTokenExpireDate = value;
            }
        }

        public class DefaultAppointAPIQueryTemplateOptionsHandler : DynamicFormItemDefineAttribute.IOptionsHandle
        {
            public List<AJTableFormSchemaItemOptions> CreateOptions()
            {
                var array = Enum.GetValues<GoodsInfoQueryTemplate>();
                var result = new List<AJTableFormSchemaItemOptions>();
                foreach (var item in array)
                {
                    var str = item.ToString();
                    result.Add(new AJTableFormSchemaItemOptions
                    {
                        Label = str,
                        Value = str
                    });
                }
                return result;
            }
        }

        public class Eledger_VehicleInfo
        {
            /// <summary>
            /// 站点id, SystemUser.Id
            /// </summary>
            [Comment("站点id")]
            public string StationId { get; set; }

            /// <summary>
            /// 车牌号
            /// </summary>
            [Comment("车牌号")]
            [Display(Name = "车牌号")]
            [Required]
            [MaxLength(120)]
            public string PlateNumber { get; set; }

            /// <summary>
            /// 卡号,用于读卡器识别车牌
            /// </summary>
            [Comment("卡号,用于读卡器识别车牌")]
            [MaxLength(100)]
            [Display(Name = "卡号")]
            public string CardNo { get; set; }

            /// <summary>
            /// 号牌颜色
            /// </summary>
            [Comment("号牌颜色")]
            [Display(Name = "号牌颜色")]
            public CarPlateColor PlateColor { get; set; }


            /// <summary>
            /// 货车车辆类型名称,  SystemDictionary.Name
            /// </summary>
            [Comment("货车车辆类型名称")]
            [Display(Name = "货车类型")]
            [MaxLength(20)]
            public string TruckTypeName { get; set; }

            /// <summary>
            /// 车辆品牌型号
            /// </summary>
            [Comment("车辆品牌型号")]
            [Display(Name = "车辆品牌型号")]
            [MaxLength(50)]
            public string CarBrandModel { get; set; }


            /// <summary>
            /// 燃料类型名称,  SystemDictionary.Name
            /// </summary>
            [Comment("燃料类型名称")]
            [Display(Name = "燃料类型")]
            [MaxLength(20)]
            public string FuelTypeName { get; set; }

            /// <summary>
            /// 排放标准
            /// </summary>
            [Comment("排放标准")]
            [Display(Name = "排放标准")]
            public EmissionStandard EmissionStandard { get; set; }

            /// <summary>
            /// 联网状态
            /// </summary>
            [Comment("联网状态")]
            [Display(Name = "联网状态")]
            public bool NetworkingStatus { get; set; }


            /// <summary>
            /// 使用性质名称
            /// </summary>
            [Comment("使用性质类型名称")]
            [Display(Name = "使用性质名称")]
            [MaxLength(100)]
            public string UsageDescription { get; set; }

            /// <summary>
            /// 发动机号
            /// </summary>
            [Comment("发动机号")]
            [Display(Name = "发动机号")]
            [MaxLength(50)]
            public string EngineNo { get; set; }

            /// <summary>
            /// 发动机型号
            /// </summary>
            [Comment("发动机型号")]
            [Display(Name = "发动机型号")]
            public string EngineModel { get; set; }

            /// <summary>
            /// 发动机生产厂
            /// </summary>
            [Comment("发动机生产厂")]
            [Display(Name = "发动机生产厂")]
            public string EngineManufacturer { get; set; }

            /// <summary>
            /// 铭牌图片Json数组文件路径
            /// </summary>
            [Comment("铭牌图片Json数组文件路径")]
            [Display(Name = "铭牌")]
            public string Nameplate { get; set; }

            /// <summary>
            /// 发动机铭牌图片Json数组文件路径
            /// </summary>
            [Comment("发动机铭牌图片Json数组文件路径")]
            [Display(Name = "发动机铭牌")]
            public string EngineNameplate { get; set; }

            /// <summary>
            /// 机械环保信息标签图片Json数组文件路径
            /// </summary>
            [Comment("机械环保信息标签图片Json数组文件路径")]
            [Display(Name = "机械环保信息标签")]
            public string MachineEnvProtectionLabel { get; set; }

            /// <summary>
            /// 排放阶段图片Json数组文件路径
            /// </summary>
            [Comment("排放阶段图片Json数组文件路径")]
            [Display(Name = "排放阶段图片")]
            public string EmissionStandardImages { get; set; }

            /// <summary>
            /// 车辆识别代码VIN
            /// </summary>
            [MaxLength(100)]
            [Comment("车辆识别代码VIN")]
            [Display(Name = "车辆识别代码VIN")]
            public string VIN { get; set; }

            /// <summary>
            /// 机械环保代码(产品识别码)PIN
            /// </summary>
            [MaxLength(100)]
            [Comment("机械环保代码(产品识别码)PIN")]
            [Display(Name = "机械环保代码")]
            public string PIN { get; set; }

            /// <summary>
            /// 环保登记编码
            /// </summary>
            [MaxLength(100)]
            [Comment("环保登记编码")]
            [Display(Name = "环保登记编码")]
            public string EnvRegCode { get; set; }

            /// <summary>
            /// 注册日期
            /// </summary>
            [Comment("注册日期")]
            [Display(Name = "注册日期")]
            
            public DateTime? RegDate { get; set; }

            /// <summary>
            /// 生产日期
            /// </summary>
            [Comment("生产日期")]
            [Display(Name = "生产日期")]
            public DateTime? ProductionDate { get; set; }

            /// <summary>
            /// 机械生产日期
            /// </summary>
            [Comment("机械生产日期")]
            [Display(Name = "机械生产日期")]
            public DateTime? MechanicalProdDate { get; set; }

            /// <summary>
            /// 机械型号
            /// </summary>
            [Comment("机械型号")]
            [Display(Name = "机械型号")]
            public string MachineModel { get; set; }

            /// <summary>
            /// 车辆所有人(单位)
            /// </summary>
            [Comment("车辆所有人(单位)")]
            [Display(Name = "所有人(单位)")]
            [MaxLength(128)]
            public string Owner { get; set; }

            /// <summary>
            /// 机械种类
            /// </summary>
            [Comment("机械种类")]
            [Display(Name = "机械种类")]
            public MachineType? MachineType { get; set; }

            /// <summary>
            /// 车队名称
            /// </summary>
            [Comment("车队名称")]
            [Display(Name = "车队名称")]
            [MaxLength(50)]
            public string TeamName { get; set; }

            /// <summary>
            /// 行驶证图片路径json数组字符串
            /// </summary>
            [Comment("行驶证图片路径json数组字符串")]
            [Display(Name = "行驶证")]
            //[AJExportField(ColumnName = "行驶证", IsImage = true)]
            public string VehicleLicense { get; set; }

            /// <summary>
            /// 随车清单路径json数组字符串
            /// </summary>
            [Comment("随车清单路径json数组字符串")]
            [Display(Name = "随车清单")]
            public string Attachments { get; set; }

            /// <summary>
            /// 车辆种类
            /// </summary>
            [Comment("车辆种类")]
            [Display(Name = "车辆种类")]
            public VehicleType VehicleType { get; set; }

            /// <summary>
            /// 最新年检日期
            /// </summary>
            [Comment("最新年检日期")]
            [Display(Name = "最新年检日期")]
            public DateTime? LatestInspectionDate { get; set; }


            /// <summary>
            /// 进厂物资名称
            /// </summary>
            [Comment("进厂物资名称")]
            [MaxLength(200)]
            [Display(Name = "进厂物资名称")]
            public string InGoodsName { get; set; }

            /// <summary>
            /// 进厂物资来源
            /// </summary>
            [Comment("进厂物资来源")]
            [MaxLength(200)]
            [Display(Name = "进厂物资来源")]
            public string InGoodsSource { get; set; }

            /// <summary>
            /// 进厂物资目的地
            /// </summary>
            [Comment("进厂物资目的地")]
            [MaxLength(200)]
            [Display(Name = "进厂物资目的地")]
            public string InGoodsDestination { get; set; }

            /// <summary>
            /// 进厂物资运输量
            /// </summary>
            [Comment("进厂物资运输量")]
            [Display(Name = "进厂物资运输量")]
            [Precision(18, 4)]
            public decimal InGoodsVolume { get; set; }

            /// <summary>
            /// 出厂物资名称
            /// </summary>
            [Comment("出厂物资名称")]
            [MaxLength(200)]
            [Display(Name = "出厂物资名称")]
            public string OutGoodsName { get; set; }

            /// <summary>
            /// 出厂物资来源
            /// </summary>
            [Comment("出厂物资来源")]
            [MaxLength(200)]
            [Display(Name = "出厂物资来源")]
            public string OutGoodsSource { get; set; }

            /// <summary>
            /// 出厂物资目的地
            /// </summary>
            [Comment("出厂物资目的地")]
            [MaxLength(200)]
            [Display(Name = "出厂物资目的地")]
            public string OutGoodsDestination { get; set; }

            /// <summary>
            /// 出厂物资运输量
            /// </summary>
            [Comment("出厂物资运输量")]
            [Display(Name = "出厂物资运输量")]
            [Precision(18, 4)]
            public decimal OutGoodsVolume { get; set; }

            /// <summary>
            /// 车辆图片路径json数组字符串
            /// </summary>
            [Comment("车辆图片路径json数组字符串")]
            [Display(Name = "车辆图片")]
            public string CarImage { get; set; }

            /// <summary>
            /// 核定载重质量
            /// </summary>
            [Comment("核定载重质量")]
            [Display(Name = "核定载重质量")]
            [StringLength(20)]
            [MaxLength(20, ErrorMessage = "{0}超长:{1}")]
            public string VerifiedLoadWeight { get; set; }

            /// <summary>
            /// 准牵引总质量
            /// </summary>
            [Comment("准牵引总质量")]
            [Display(Name = "准牵引总质量")]
            [StringLength(20)]
            [MaxLength(20, ErrorMessage = "{0}超长:{1}")]
            public string PermittedTowingWeight { get; set; }

            /// <summary>
            /// 预留1
            /// </summary>
            [Comment("预留1")]
            [Display(Name = "预留1")]
            public string Reserve1 { get; set; }

            /// <summary>
            /// 预留2
            /// </summary>
            [Comment("预留2")]
            [Display(Name = "预留2")]
            public string Reserve2 { get; set; }

            /// <summary>
            /// 预留3
            /// </summary>
            [Comment("预留3")]
            [Display(Name = "预留3")]
            public string Reserve3 { get; set; }

            /// <summary>
            /// 预留4
            /// </summary>
            [Comment("预留4")]
            [Display(Name = "预留4")]
            public string Reserve4 { get; set; }

            /// <summary>
            /// 预留5
            /// </summary>
            [Comment("预留5")]
            [Display(Name = "预留5")]
            public string Reserve5 { get; set; }

            /// <summary>
            /// 预留6
            /// </summary>
            [Comment("预留6")]
            [Display(Name = "预留6")]
            public string Reserve6 { get; set; }

            /// <summary>
            /// 预留7
            /// </summary>
            [Comment("预留7")]
            [Display(Name = "预留7")]
            public string Reserve7 { get; set; }

            /// <summary>
            /// 预留8
            /// </summary>
            [Comment("预留8")]
            [Display(Name = "预留8")]
            public string Reserve8 { get; set; }

            /// <summary>
            /// 预留9
            /// </summary>
            [Comment("预留9")]
            [Display(Name = "预留9")]
            public string Reserve9 { get; set; }

            /// <summary>
            /// 预留10
            /// </summary>
            [Comment("预留10")]
            [Display(Name = "预留10")]
            public string Reserve10 { get; set; }

            /// <summary>
            /// 预留11
            /// </summary>
            [Comment("预留11")]
            [Display(Name = "预留11")]
            public string Reserve11 { get; set; }

            /// <summary>
            /// 预留12
            /// </summary>
            [Comment("预留12")]
            [Display(Name = "预留12")]
            public string Reserve12 { get; set; }

            /// <summary>
            /// 预留13
            /// </summary>
            [Comment("预留13")]
            [Display(Name = "预留13")]
            public string Reserve13 { get; set; }

            /// <summary>
            /// 预留14
            /// </summary>
            [Comment("预留14")]
            [Display(Name = "预留14")]
            public string Reserve14 { get; set; }

            /// <summary>
            /// 预留15
            /// </summary>
            [Comment("预留15")]
            [Display(Name = "预留15")]
            public string Reserve15 { get; set; }

            /// <summary>
            /// 预留16
            /// </summary>
            [Comment("预留16")]
            [Display(Name = "预留16")]
            public string Reserve16 { get; set; }

            /// <summary>
            /// 预留17
            /// </summary>
            [Comment("预留17")]
            [Display(Name = "预留17")]
            public string Reserve17 { get; set; }

            /// <summary>
            /// 预留18
            /// </summary>
            [Comment("预留18")]
            [Display(Name = "预留18")]
            public string Reserve18 { get; set; }

            /// <summary>
            /// 预留19
            /// </summary>
            [Comment("预留19")]
            [Display(Name = "预留19")]
            public string Reserve19 { get; set; }

            /// <summary>
            /// 预留20
            /// </summary>
            [Comment("预留20")]
            [Display(Name = "预留20")]
            public string Reserve20 { get; set; }

            /// <summary>
            /// 关联Customer.id
            /// </summary>
            [Comment("关联Customer.id")]
            public long CustomerId { get; set; }

            public void FillTo(ref Car car)
            {
                var modelProps = this.GetType().GetRuntimeProperties();

                var carType = car.GetType();

                foreach (var modelProp in modelProps)
                {
                    if (modelProp.Name == nameof(UsageDescription)
                        || modelProp.Name == nameof(FuelTypeName)
                        || modelProp.Name == nameof(TruckTypeName)
                        || modelProp.Name == nameof(PlateNumber))
                    {
                        continue;
                    }

                    var modelVal = modelProp.GetValue(this);
                    if(modelVal == null)
                    {
                        continue;
                    }

                    var targetProp = carType.GetProperty(modelProp.Name);

                    if(targetProp == null)
                    {
                        continue;
                    }

                    targetProp.SetValue(car, modelVal);
                }
            }
        }

        public class CarInfoAPIResponseData
        {
            /// <summary>
            /// 
            /// </summary>
            public int id { get; set; }
            /// <summary>
            /// 张安帮
            /// </summary>
            public string companyname { get; set; }
            /// <summary>
            /// 豫HR8697
            /// </summary>
            public string plateNumber { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string vin { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string engineNumber { get; set; }
            /// <summary>
            /// 黄色
            /// </summary>
            public string carColor { get; set; }
            /// <summary>
            /// 大运牌CGC4250D5ECCE
            /// </summary>
            public string carModel { get; set; }
            /// <summary>
            /// 重型半挂牵引车
            /// </summary>
            public string carType { get; set; }
            /// <summary>
            /// 燃油类型-B柴油
            /// </summary>
            public string useNNature { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string registerTime { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string issueTime { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string createtime { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string updatetime { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string status { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string driving_image { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string list_image { get; set; }
            /// <summary>
            /// 山东天铭重工科技股份有限公司
            /// </summary>
            public string danwei { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string comment { get; set; }
            /// <summary>
            /// 国5
            /// </summary>
            public string emissionstage { get; set; }
            /// <summary>
            /// 个体
            /// </summary>
            public string fleet { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string temperature { get; set; }
            /// <summary>
            /// 耐火砖
            /// </summary>
            public string goods { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string goodsUnit { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string carrierUnit { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string inputPersonMobile { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string owner { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string ownerAddress { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string driverName { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string driverMobile { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string carImage { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string envLabelImage { get; set; }
            /// <summary>
            /// 使用性质-货运
            /// </summary>
            public string operationLicenseImage { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string expire_at { get; set; }
        }

        public class CarInfoAPIResponse
        {
            /// <summary>
            /// 
            /// </summary>
            public int code { get; set; }
            /// <summary>
            /// 返回成功
            /// </summary>
            public string msg { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string time { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public CarInfoAPIResponseData data { get; set; }

            public bool success
            {
                get { return code == 1; }
                set { code = value ? 1 : 0; }
            }
        }
    }
}
